package logic

import (
	"MyBlogv2/blog-common/HttpCode"
	"MyBlogv2/blog-common/models"
	"context"
	"github.com/jinzhu/copier"

	"MyBlogv2/Servers/Article/article"
	"MyBlogv2/Servers/Article/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type GetHotArticleListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGetHotArticleListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetHotArticleListLogic {
	return &GetHotArticleListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *GetHotArticleListLogic) GetHotArticleList(in *Article.ArticleRequest) (*Article.GetHotArticleListResponse, error) {
	var hotArticleVoList []models.HotArticleVo
	models.Db.Model(new(models.HotArticleVo)).Order("visit_count desc").Limit(5).Find(&hotArticleVoList)
	var hotArticleVoListResponse []*Article.HotArticleVo
	copier.Copy(&hotArticleVoListResponse, &hotArticleVoList)

	return &Article.GetHotArticleListResponse{
		Code: int64(HttpCode.SUCCESS),
		Data: hotArticleVoListResponse,
	}, nil
}
